package com.markus.code.排序;

/**
 * Author:markusZhang
 * Date:Create in 2020/8/21 23:50
 * todo: 合并两个排序的数组
 */
public class LeetCode_88 {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int []temp = new int[m+n];
        int index = 0;
        int left = 0;
        int right = 0;
        while(left < m && right < n){
            if (nums1[left] <= nums2[right]){
                temp[index++] = nums1[left++];
            }else{
                temp[index++] = nums2[right++];
            }
        }
        while(left < m){
            temp[index++] = nums1[left++];
        }
        while(right < n){
            temp[index++] = nums2[right++];
        }
        for (int i=0;i<m+n;i++){
            nums1[i] = temp[i];
        }
    }
}
